// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Ml
{
	public sealed class MlPreviewDatafeedRequestParameters : RequestParameters<MlPreviewDatafeedRequestParameters>
	{
	}

	public sealed partial class MlPreviewDatafeedRequest : PlainRequestBase<MlPreviewDatafeedRequestParameters>
	{
		public MlPreviewDatafeedRequest()
		{
		}

		public MlPreviewDatafeedRequest(Elastic.Clients.Elasticsearch.Id? datafeed_id) : base(r => r.Optional("datafeed_id", datafeed_id))
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningPreviewDatafeed;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		[JsonInclude]
		[JsonPropertyName("datafeed_config")]
		public Elastic.Clients.Elasticsearch.Ml.DatafeedConfig? DatafeedConfig { get; set; }

		[JsonInclude]
		[JsonPropertyName("job_config")]
		public Elastic.Clients.Elasticsearch.Ml.JobConfig? JobConfig { get; set; }
	}

	public sealed partial class MlPreviewDatafeedRequestDescriptor<TDocument> : RequestDescriptorBase<MlPreviewDatafeedRequestDescriptor<TDocument>, MlPreviewDatafeedRequestParameters>
	{
		internal MlPreviewDatafeedRequestDescriptor(Action<MlPreviewDatafeedRequestDescriptor<TDocument>> configure) => configure.Invoke(this);
		public MlPreviewDatafeedRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningPreviewDatafeed;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		public MlPreviewDatafeedRequestDescriptor<TDocument> DatafeedId(Elastic.Clients.Elasticsearch.Id? datafeed_id)
		{
			RouteValues.Optional("datafeed_id", datafeed_id);
			return Self;
		}

		private Elastic.Clients.Elasticsearch.Ml.DatafeedConfig? DatafeedConfigValue { get; set; }

		private DatafeedConfigDescriptor<TDocument> DatafeedConfigDescriptor { get; set; }

		private Action<DatafeedConfigDescriptor<TDocument>> DatafeedConfigDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.JobConfig? JobConfigValue { get; set; }

		private JobConfigDescriptor<TDocument> JobConfigDescriptor { get; set; }

		private Action<JobConfigDescriptor<TDocument>> JobConfigDescriptorAction { get; set; }

		public MlPreviewDatafeedRequestDescriptor<TDocument> DatafeedConfig(Elastic.Clients.Elasticsearch.Ml.DatafeedConfig? datafeedConfig)
		{
			DatafeedConfigDescriptor = null;
			DatafeedConfigDescriptorAction = null;
			DatafeedConfigValue = datafeedConfig;
			return Self;
		}

		public MlPreviewDatafeedRequestDescriptor<TDocument> DatafeedConfig(DatafeedConfigDescriptor<TDocument> descriptor)
		{
			DatafeedConfigValue = null;
			DatafeedConfigDescriptorAction = null;
			DatafeedConfigDescriptor = descriptor;
			return Self;
		}

		public MlPreviewDatafeedRequestDescriptor<TDocument> DatafeedConfig(Action<DatafeedConfigDescriptor<TDocument>> configure)
		{
			DatafeedConfigValue = null;
			DatafeedConfigDescriptor = null;
			DatafeedConfigDescriptorAction = configure;
			return Self;
		}

		public MlPreviewDatafeedRequestDescriptor<TDocument> JobConfig(Elastic.Clients.Elasticsearch.Ml.JobConfig? jobConfig)
		{
			JobConfigDescriptor = null;
			JobConfigDescriptorAction = null;
			JobConfigValue = jobConfig;
			return Self;
		}

		public MlPreviewDatafeedRequestDescriptor<TDocument> JobConfig(JobConfigDescriptor<TDocument> descriptor)
		{
			JobConfigValue = null;
			JobConfigDescriptorAction = null;
			JobConfigDescriptor = descriptor;
			return Self;
		}

		public MlPreviewDatafeedRequestDescriptor<TDocument> JobConfig(Action<JobConfigDescriptor<TDocument>> configure)
		{
			JobConfigValue = null;
			JobConfigDescriptor = null;
			JobConfigDescriptorAction = configure;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (DatafeedConfigDescriptor is not null)
			{
				writer.WritePropertyName("datafeed_config");
				JsonSerializer.Serialize(writer, DatafeedConfigDescriptor, options);
			}
			else if (DatafeedConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("datafeed_config");
				JsonSerializer.Serialize(writer, new DatafeedConfigDescriptor<TDocument>(DatafeedConfigDescriptorAction), options);
			}
			else if (DatafeedConfigValue is not null)
			{
				writer.WritePropertyName("datafeed_config");
				JsonSerializer.Serialize(writer, DatafeedConfigValue, options);
			}

			if (JobConfigDescriptor is not null)
			{
				writer.WritePropertyName("job_config");
				JsonSerializer.Serialize(writer, JobConfigDescriptor, options);
			}
			else if (JobConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("job_config");
				JsonSerializer.Serialize(writer, new JobConfigDescriptor<TDocument>(JobConfigDescriptorAction), options);
			}
			else if (JobConfigValue is not null)
			{
				writer.WritePropertyName("job_config");
				JsonSerializer.Serialize(writer, JobConfigValue, options);
			}

			writer.WriteEndObject();
		}
	}

	public sealed partial class MlPreviewDatafeedRequestDescriptor : RequestDescriptorBase<MlPreviewDatafeedRequestDescriptor, MlPreviewDatafeedRequestParameters>
	{
		internal MlPreviewDatafeedRequestDescriptor(Action<MlPreviewDatafeedRequestDescriptor> configure) => configure.Invoke(this);
		public MlPreviewDatafeedRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningPreviewDatafeed;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		public MlPreviewDatafeedRequestDescriptor DatafeedId(Elastic.Clients.Elasticsearch.Id? datafeed_id)
		{
			RouteValues.Optional("datafeed_id", datafeed_id);
			return Self;
		}

		private Elastic.Clients.Elasticsearch.Ml.DatafeedConfig? DatafeedConfigValue { get; set; }

		private DatafeedConfigDescriptor DatafeedConfigDescriptor { get; set; }

		private Action<DatafeedConfigDescriptor> DatafeedConfigDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.JobConfig? JobConfigValue { get; set; }

		private JobConfigDescriptor JobConfigDescriptor { get; set; }

		private Action<JobConfigDescriptor> JobConfigDescriptorAction { get; set; }

		public MlPreviewDatafeedRequestDescriptor DatafeedConfig(Elastic.Clients.Elasticsearch.Ml.DatafeedConfig? datafeedConfig)
		{
			DatafeedConfigDescriptor = null;
			DatafeedConfigDescriptorAction = null;
			DatafeedConfigValue = datafeedConfig;
			return Self;
		}

		public MlPreviewDatafeedRequestDescriptor DatafeedConfig(DatafeedConfigDescriptor descriptor)
		{
			DatafeedConfigValue = null;
			DatafeedConfigDescriptorAction = null;
			DatafeedConfigDescriptor = descriptor;
			return Self;
		}

		public MlPreviewDatafeedRequestDescriptor DatafeedConfig(Action<DatafeedConfigDescriptor> configure)
		{
			DatafeedConfigValue = null;
			DatafeedConfigDescriptor = null;
			DatafeedConfigDescriptorAction = configure;
			return Self;
		}

		public MlPreviewDatafeedRequestDescriptor JobConfig(Elastic.Clients.Elasticsearch.Ml.JobConfig? jobConfig)
		{
			JobConfigDescriptor = null;
			JobConfigDescriptorAction = null;
			JobConfigValue = jobConfig;
			return Self;
		}

		public MlPreviewDatafeedRequestDescriptor JobConfig(JobConfigDescriptor descriptor)
		{
			JobConfigValue = null;
			JobConfigDescriptorAction = null;
			JobConfigDescriptor = descriptor;
			return Self;
		}

		public MlPreviewDatafeedRequestDescriptor JobConfig(Action<JobConfigDescriptor> configure)
		{
			JobConfigValue = null;
			JobConfigDescriptor = null;
			JobConfigDescriptorAction = configure;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (DatafeedConfigDescriptor is not null)
			{
				writer.WritePropertyName("datafeed_config");
				JsonSerializer.Serialize(writer, DatafeedConfigDescriptor, options);
			}
			else if (DatafeedConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("datafeed_config");
				JsonSerializer.Serialize(writer, new DatafeedConfigDescriptor(DatafeedConfigDescriptorAction), options);
			}
			else if (DatafeedConfigValue is not null)
			{
				writer.WritePropertyName("datafeed_config");
				JsonSerializer.Serialize(writer, DatafeedConfigValue, options);
			}

			if (JobConfigDescriptor is not null)
			{
				writer.WritePropertyName("job_config");
				JsonSerializer.Serialize(writer, JobConfigDescriptor, options);
			}
			else if (JobConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("job_config");
				JsonSerializer.Serialize(writer, new JobConfigDescriptor(JobConfigDescriptorAction), options);
			}
			else if (JobConfigValue is not null)
			{
				writer.WritePropertyName("job_config");
				JsonSerializer.Serialize(writer, JobConfigValue, options);
			}

			writer.WriteEndObject();
		}
	}
}